package com.ant.user.utils;

import org.mindrot.jbcrypt.BCrypt;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class PasswordUtil {
    // 哈希密码
    public static String hashPassphrase(String passphrase) {
        return BCrypt.hashpw(passphrase, BCrypt.gensalt());
    }

    // 验证密码
    public static boolean verifyPassphrase(String passphrase, String hashedPassphrase) {
        return BCrypt.checkpw(passphrase, hashedPassphrase);
    }

    public static boolean validatePassphrase(String password) {
        String regex = "^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)(?=.*[-+_=]).{8,}$";
        Pattern pattern = Pattern.compile(regex);
        Matcher matcher = pattern.matcher(password);
        return matcher.matches();
    }
}
